package com.pll.config;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @ClassName RateLimiterConfig
 * @Description TODO
 * @Author 小鹿
 * @Date 2025/5/26 9:49
 */
@Configuration
public class RateLimiterConfig
{
    @Bean
    public KeyResolver userResolver(){
        KeyResolver keyResolver = new KeyResolver()
        {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange)
            {
                String ip = exchange.getRequest().getRemoteAddress().getAddress().toString();
                return Mono.just(ip);
            }
        };
        return keyResolver;
    }
}